package com.chinabank.dao.impl;

import java.io.Serializable;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import com.chinabank.dao.BaseDao;


public abstract class BaseDaoImpl<T> implements BaseDao<T>{

	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	@Resource
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public T get(Class<T> cls, Serializable id) {
		Session session = sessionFactory.getCurrentSession();
		T t = (T)session.get(cls, id);
		return t;
	}

	@Override
	public void delete(T obj) {
		Session session = sessionFactory.getCurrentSession();
		session.delete(obj);
	}

	@Override
	public void update(T obj) {
		Session session = sessionFactory.getCurrentSession();
		session.update(obj);
	}

	@Override
	public void add(T obj) {
		Session session = sessionFactory.getCurrentSession();
		session.save(obj);
	}



}
